import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

class Ventana extends JFrame implements ActionListener {
    private JPanel panelPpal = new JPanel ();
    private JPanel panelSup = new JPanel ();
    private JPanel panelBulto = new JPanel ();
    private JPanel panelBulto2 = new JPanel ();
    private JPanel panelInf = new JPanel ();
    private JPanel panelInfW = new JPanel ();
    private JPanel panelInfE = new JPanel ();
    private JPanel panelBoton = new JPanel ();
    private JLabel lOriginal = new JLabel("Moneda original:", JLabel.LEFT);
    private JLabel lConvertida = new JLabel("Moneda convertida:", JLabel.LEFT);
    private JLabel lCantidad = new JLabel("Cantidad que desea convertir:", JLabel.LEFT);
    private JLabel lResultado = new JLabel("Resultado:", JLabel.LEFT);
    private JTextField tCantidad = new JTextField();
    private JTextField tResultado = new JTextField();
    private String[] listaMonedas = {   "Euro (Europa)", 
                                        "Dólar (EEUU)", 
                                        "Balboa (Panamá)", 
                                        "Bath (Tailandia)", 
                                        "Birr (Etiopía)", 
                                        "Bolivar (Venezuela)", 
                                        "Cedi (Ghana)", 
                                        "Chelín (Kenya)", 
                                        "Colón (Cost. Rica)", 
                                        "Colón (El Salvador)", 
                                        "Córdoba (Nicaragua)", 
                                        "Corona (Dinamarca)", 
                                        "Corona (Eslovaquia)", 
                                        "Corona (Estonia)", 
                                        "Corona (Islandia)", 
                                        "Corona (Noruega)", 
                                        "Corona (Rep. Checa)", 
                                        "Corona (Suecia)", 
                                        "Dinar (Argelia)",
                                        "Dinar (Bahrain)",
                                        "Dinar (Irak)",
                                        "Dinar (Jordania)",
                                        "Dinar (Kuwait)",
                                        "Dinar (Libia)",
                                        "Dinar (Serbia)",
                                        "Dirham (Est. Arabes Uni.)",
                                        "Dirham (Marruecos)",
                                        "Dólar (Australia)", 
                                        "Dólar (Bahamas)", 
                                        "Dólar (Barbados)", 
                                        "Dólar (Belice)", 
                                        "Dólar (Bermuda)", 
                                        "Dólar (Canadá)", 
                                        "Dólar (Ecuador)", 
                                        "Dólar (Fidji)", 
                                        "Dólar (Guyana)", 
                                        "Dólar (Hong Kong)",
                                        "Dólar (Jamaica)",
                                        "Dólar (Nueva Zelanda)",
                                        "Dólar (Puerto Rico)",
                                        "Dólar (Singapur)", 
                                        "Dólar (Surinam)", 
                                        "Dólar (Trin. y Tobago)",
                                        "Dong (Vietnam)", 
                                        "Franco (Afr. Central)",
                                        "Franco (Rep. Congo)",
                                        "Franco (Suiza)",
                                        "Forint (Hungría)",
                                        "Gourde (Haití)",
                                        "Guaraní (Paraguay)",
                                        "Hryvna (Ucrania)",
                                        "Lek (Albania)",
                                        "Lempira (Honduras)",
                                        "Leu (Rumania)",
                                        "Lev (Bulgaria)",
                                        "Libra (Egipto)",
                                        "Libra (Líbano)",
                                        "Libra (Siria)",
                                        "Libra Esterlina (GB)",
                                        "Lira (Turquía)",
                                        "Litas (Lituania)",
                                        "Naira (Nigeria)",
                                        "Nuevo Sol (Perú)",
                                        "Nuevo Dólar (Taiwan)",
                                        "Peso (Argentina)",
                                        "Peso (Chile)",
                                        "Peso (Colombia)",
                                        "Peso (Cuba)",
                                        "Peso (Filipinas)",
                                        "Peso (Rep. Dominicana)",
                                        "Peso (Uruguay)",
                                        "Quetzal (Guatemala)",
                                        "Rand (Rep. Sudáfrica)",
                                        "Real (Brasil)",
                                        "Rial (Rep. Yemen)",
                                        "Rial (Rep. Isl. de Irán)",
                                        "Ringgit (Malasia)",
                                        "Riyal (Arabia Saudita)",
                                        "Rublo (Fed. Rusa)",
                                        "Rupia (India)",
                                        "Rupia (Pakistan)",
                                        "Rupia (Sri-Lanka)",
                                        "Shekel (Israel)",
                                        "Won (Corea del Norte)",
                                        "Won (Corea del Sur)",
                                        "Yuan (China)",
                                        "Yen (Japón)",
                                        "Zloty (Polonia)",
                                    };
    private double[] valorMonedas = {   1.32950,
                                        1.0,
                                        1.0,
                                        0.03092,
                                        0.074,
                                        0.23285,
                                        0.07053,
                                        0.01302,
                                        0.00195,
                                        0.11432,
                                        0.04722,
                                        0.17874,
                                        0.04416,
                                        0.08503,
                                        0.00782,
                                        0.16927,
                                        0.05204,
                                        0.13817,
                                        0.01362,
                                        2.65259,
                                        0.00086,
                                        1.41183,
                                        3.46380,
                                        0.78272,
                                        0.01336,
                                        0.27226,
                                        0.11921,
                                        0.93080,
                                        1.0,
                                        0.5,
                                        0.51282,
                                        1.0,
                                        0.98765,
                                        1.0,
                                        0.52090,
                                        0.00489,
                                        0.12881,
                                        0.01117,
                                        0.73160,
                                        1.0,
                                        0.71220,
                                        0.36430,
                                        0.15748,
                                        0.05275,
                                        0.00203,
                                        0.00112,
                                        0.92782,
                                        0.00497,
                                        0.02516,
                                        0.21186,
                                        0.12618,
                                        0.00966,
                                        0.05292,
                                        0.03221,
                                        0.68004,
                                        0.1799,
                                        0.66624,
                                        0.0216,
                                        1.5315,
                                        0.67336,
                                        0.38531,
                                        0.00662,
                                        0.35125,
                                        0.03191,
                                        0.25737,
                                        0.00194,
                                        0.51233,
                                        1.0,
                                        0.02249,
                                        0.02719,
                                        0.05195,
                                        0.12462,
                                        0.13598,
                                        0.57777,
                                        0.00443,
                                        0.10102,
                                        0.31409,
                                        0.26665,
                                        0.03423,
                                        0.02254,
                                        0.01190,
                                        0.00878,
                                        0.2688,
                                        0.0069,
                                        0.90228,
                                        0.14651,
                                        0.01064,
                                        0.33944
                                    };
    private JComboBox cbOriginal = new JComboBox(listaMonedas);
    private JComboBox cbConvertida = new JComboBox(listaMonedas);
    private JButton bConvertir = new JButton("CONVERTIR");
    
    public Ventana (){
        setTitle("Conversor de monedas (Valor del 06-04-2010)");
        setSize(700,160);
        
        panelPpal.setLayout (new GridLayout (2,1));
        panelSup.setLayout (new GridLayout (2,3));
        panelInf.setLayout (new GridLayout (1,3));
        panelInfE.setLayout (new GridLayout (2,1));
        panelInfW.setLayout (new GridLayout (2,1));
        
        panelSup.add (lOriginal);
        panelSup.add (panelBulto);
        panelSup.add (lConvertida);
        panelSup.add (cbOriginal);
        panelSup.add (panelBulto2);
        panelSup.add (cbConvertida);
        
        cbOriginal.setForeground(new java.awt.Color(58, 148, 250));
        cbConvertida.setForeground(new java.awt.Color(58, 148, 250));
        tResultado.setForeground(new java.awt.Color(58, 148, 250));
        tCantidad.setForeground(new java.awt.Color(58, 148, 250));
        lResultado.setForeground(new java.awt.Color(58, 148, 250));
        
        tResultado.setEditable(false);
        
        cbOriginal.setSelectedIndex(0);
        cbConvertida.setSelectedIndex(1);
        
        panelInfE.add (lCantidad);
        panelInfE.add (tCantidad);
        
        panelInfW.add (lResultado);
        panelInfW.add (tResultado);
        
        panelBoton.add (bConvertir);
        
        panelInf.add (panelInfE);
        panelInf.add (panelBoton);
        panelInf.add (panelInfW);
        
        panelBoton.setLayout(null);
        bConvertir.setBounds(new Rectangle(55,30,120,20));

        
        panelSup.setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8));
        panelInfE.setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8));
        panelInfW.setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8));
        
        panelPpal.add (panelSup);
        panelPpal.add (panelInf);
        
        add (panelPpal);
        
        bConvertir.addActionListener (this);
    }
    
    public void actionPerformed(ActionEvent evento) {
        Object source = evento.getSource();
        double or;
        
        if (source == bConvertir) {
            try {
                or = Double.parseDouble(tCantidad.getText());
                tResultado.setText("" + or * valorMonedas[cbOriginal.getSelectedIndex()] / valorMonedas[cbConvertida.getSelectedIndex()]);
            }
            catch (java.lang.NumberFormatException n) {
                JOptionPane.showMessageDialog( Ventana.this, "Los parametros de entrada son incorrectos.", "ERROR!!", JOptionPane.PLAIN_MESSAGE );
            }
        }
    }
}

public class ConversorSimple {
    public static void main (String[] args){
        Ventana  v = new Ventana();        
        v.setLocationRelativeTo(null);           
        v.setVisible(true);
        v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
